package com.keiou.drink.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keiou.drink.R;
import com.keiou.drink.response.OrderHistoryRes;
import com.keiou.drink.util.TimeUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者 ：Bob on 2017/10/30.
 * 邮箱 ：motherlovefather@126.com
 */

public class OrderHistoryAdapter extends RecyclerView.Adapter<OrderHistoryAdapter.ViewHolder> {

    private List<OrderHistoryRes.OrderBean> list;
    private LayoutInflater mInflater;

    public OrderHistoryAdapter(Context context, List<OrderHistoryRes.OrderBean> list) {
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View root = mInflater.inflate(R.layout.item_order_history, parent, false);
        ViewHolder holder = new ViewHolder(root);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        OrderHistoryRes.OrderBean bean = list.get(position);
        holder.tvNum.setText(position + 1 + "");
        holder.tvPrice.setText(bean.getSalesPrice() + "");
        holder.tvCount.setText(bean.getCount() + "");
        holder.tvTotalPrice.setText(bean.getAmount() + "");
        holder.tvDate.setText(TimeUtil.getDate(bean.getOrderDt()));
        holder.tvName.setText(bean.getProductName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.tv_num)
        TextView tvNum;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_count)
        TextView tvCount;
        @BindView(R.id.tv_total_price)
        TextView tvTotalPrice;
        @BindView(R.id.tv_date)
        TextView tvDate;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
